import { aesCBCEncrypt } from '@/utils/common'
import { io } from './io'

export const login = (data: Api.Auth.LoginPrarams) => {
    const { mobileNumber, password } = data
    console.log(mobileNumber, password)
    const s = aesCBCEncrypt(password, 'C1coeljwe123&2*1klj81#dJ29tY08iV')
    console.log(s)
    return io<Api.Auth.Login>({
        url: '/api/v1/user/admin/login',
        method: 'POST',
        data: {
            mobileNumber,
            password: s
        }
    })
}
interface GoogleRecaptchaResult {
    success: boolean
    challenge_ts?: string
    hostname?: string
    score?: number
    action?: string
}
interface GoogleRecaptchaPayload {
    'g-recaptcha-response': string
}
export const verifyRecaptcha = (data: { token: string }) => {
    return io<GoogleRecaptchaResult>({
        url: '/api/v1/verify-recaptcha',
        method: 'POST',
        data
    })
}

export const queryUserLit = (params: Api.User.UserSearchParams) =>
    io<Api.User.UserList>({
        url: '/api/v1/user/list',
        method: 'GET',
        params
    })

export const queryUserDetail = (userId: number) =>
    io<Api.User.UserDetail>({
        url: `/api/v1/user/info/${userId}`,
        method: 'GET'
    })

export const updateUserStatus = (userId: number, status: Api.User.UserDetail['status']) =>
    io<boolean>({
        url: `/api/v1/user/status/${userId}`,
        method: 'PUT',
        data: {
            status
        }
    })

export const queryAgentLit = (params: Api.User.AgentSearchParams) =>
    io<Api.User.UserList>({
        url: '/api/v1/user/agent/list',
        method: 'GET',
        params
    })

export const queryAgentDetail = (userId: number) =>
    io<Api.User.AgentDetail>({
        url: `/api/v1/user/agent/info/${userId}`,
        method: 'GET'
    })

export const updateAgentStatus = (userId: number, agentStatus: Api.User.AgentDetail['agentStatus']) =>
    io<boolean>({
        url: `/api/v1/user/agent/status/${userId}`,
        method: 'PUT',
        data: {
            agentStatus
        }
    })

export const queryFund = () =>
    io<Api.User.Fund>({
        url: '/api/v1/user/fund/info',
        method: 'GET'
    })

export const querySMSList = (params: Api.User.SMSSearchParams) =>
    io<Api.User.SMSList>({
        url: '/api/v1/user/smscode/list',
        method: 'GET',
        params
    })
